{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 练习1: 打印2,4,6,8,10,...,100"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,"
     ]
    }
   ],
   "source": [
    "i = 2\n",
    "while i<=100:\n",
    "    print(i,end=\",\")\n",
    "    i+=2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 练习2: 让用户输入数字n,打印如下序列:1 2 4 8 16 32 64 128 256 ... 2^n\n",
    "  （需要嵌套循环)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2 4 8 16 32 64 128 256 512 "
     ]
    }
   ],
   "source": [
    "n = int(input(\"请输入n:\"))\n",
    "i = 1\n",
    "print(1,end=\" \")\n",
    "while i<n:\n",
    "    s = 1\n",
    "    j = 0\n",
    "    while j<i: \n",
    "        s *= 2\n",
    "        j += 1\n",
    "    print(s,end=\" \")\n",
    "    i += 1\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 练习3: 让用户输入数字，并计算总和，如果总和超过60，则终止，打印最后总和是多少"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "120\n",
      "总和: 130\n"
     ]
    }
   ],
   "source": [
    "s = 0\n",
    "while s<=60:\n",
    "    n = int(input(\"请输入一个数字:\"))\n",
    "    print(n)\n",
    "    s += n\n",
    "print(\"总和:\",s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
